<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">

        <ui:define name="title">
            <h:outputText value="#{bundle.ListTurmaTitle}"></h:outputText>
        </ui:define>

        <ui:define name="body">

            <h:panelGroup id="messagePanel" layout="block">
                <p:growl />
            </h:panelGroup>

            <h:form id="formTurmaList">

                <h:panelGroup>

                    <p:dataTable id="tableTurma" value="#{turmaController.items}" var="item" 
                                 emptyMessage="#{bundle.ListTurmaEmpty}" paginator="true" rows="10" >

                        <f:facet name="header">#{bundle.ListTurmaTitle}</f:facet>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListTurmaTitle_descricao}"/>
                            </f:facet>
                            <h:outputText value="#{item.descricao}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListTurmaTitle_horario}"/>
                            </f:facet>
                            <h:outputText value="#{item.horario.toString()}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListTurmaTitle_professor}"/>
                            </f:facet>
                            <h:outputText value="#{item.professor.nome}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListTurmaTitle_modalidade}"/>
                            </f:facet>
                            <h:outputText value="#{item.modalidade.descricao}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <p:commandButton actionListener="#{turmaController.prepareCreate}" 
                                                 value="#{bundle.ListTurmaCreateLink}"
                                                 update=":formTurmaCreate:pgTurmaCreate" 
                                                 oncomplete="dialogTurmaCreate.show()"/>
                            </f:facet>
                            <p:commandButton actionListener="#{turmaController.prepareEdit}" 
                                             value="#{bundle.ListTurmaEditLink}"
                                             update=":formTurmaEdit:pgTurmaEdit" 
                                             oncomplete="dialogTurmaEdit.show()" />
                            <p:commandButton actionListener="#{turmaController.destroy}" 
                                             value="#{bundle.ListTurmaDestroyLink}" ajax="false"/>

                        </p:column>
                    </p:dataTable>

                </h:panelGroup>

            </h:form>

            <h:form id="formTurmaCreate">

                <p:dialog header="#{bundle.CreateTurmaTitle}" widgetVar="dialogTurmaCreate" 
                          resizable="false" modal="true" showEffect="slide">
                    <p:panelGrid id="pgTurmaCreate" columns="2">

                        <h:outputLabel value="#{bundle.CreateTurmaLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{turmaController.selected.descricao}" 
                                     title="#{bundle.CreateTurmaTitle_descricao}" required="true"
                                     requiredMessage="#{bundle.CreateTurmaRequiredMessage_descricao}"/>

                        <h:outputLabel value="#{bundle.CreateTurmaLabel_horario}" for="horario" />
                        <p:selectOneMenu id="horario" value="#{turmaController.selected.horario}" 
                                         label="#{bundle.CreateTurmaTitle_horario}" required="true" 
                                         requiredMessage="#{bundle.CreateTurmaRequiredMessage_horario}">
                            <f:selectItems value="#{horarioController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>

                        <h:outputLabel value="#{bundle.CreateTurmaLabel_professor}" for="professor" />
                        <p:selectOneMenu id="professor" value="#{turmaController.selected.professor}" 
                                         label="#{bundle.CreateTurmaTitle_professor}" required="true" 
                                         requiredMessage="#{bundle.CreateTurmaRequiredMessage_professor}">
                            <f:selectItems value="#{funcionarioController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        
                        <h:outputLabel value="#{bundle.CreateTurmaLabel_modalidade}" for="modalidade" />
                        <p:selectOneMenu id="modalidade" value="#{turmaController.selected.modalidade}" 
                                         label="#{bundle.CreateTurmaTitle_modalidade}" required="true" 
                                         requiredMessage="#{bundle.CreateTurmaRequiredMessage_modalidade}">
                            <f:selectItems value="#{modalidadeController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>

                        <p:commandButton actionListener="#{turmaController.create}" 
                                         update=":formTurmaList:tableTurma" 
                                         value="#{bundle.CreateTurmaSaveLink}" 
                                         oncomplete="#{turmaController.prepareCreate}" ajax="false" />
                        <p:commandButton value="Limpar" type="reset" 
                                         update=":formTurmaCreate:pgTurmaCreate" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>

            </h:form>

            <h:form id="formTurmaEdit">

                <p:dialog header="#{bundle.EditTurmaTitle}" widgetVar="dialogTurmaEdit" resizable="false" modal="true" showEffect="slide">
                    <p:panelGrid id="pgTurmaEdit" columns="2">
                        
                        <h:outputLabel value="#{bundle.EditTurmaLabel_descricao}" for="descricao" />
                        <p:inputText id="descricao" value="#{turmaController.selected.descricao}" 
                                     title="#{bundle.EditTurmaTitle_descricao}" required="true"
                                     requiredMessage="#{bundle.EditTurmaRequiredMessage_descricao}"/>

                        <h:outputLabel value="#{bundle.EditTurmaLabel_horario}" for="horario" />
                        <p:selectOneMenu id="horario" value="#{turmaController.selected.horario}" 
                                         label="#{bundle.EditTurmaTitle_horario}" required="true" 
                                         requiredMessage="#{bundle.EditTurmaRequiredMessage_horario}">
                            <f:selectItems value="#{horarioController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>

                        <h:outputLabel value="#{bundle.EditTurmaLabel_professor}" for="professor" />
                        <p:selectOneMenu id="professor" value="#{turmaController.selected.professor}" 
                                         label="#{bundle.EditTurmaTitle_professor}" required="true" 
                                         requiredMessage="#{bundle.EditTurmaRequiredMessage_professor}">
                            <f:selectItems value="#{funcionarioController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>
                        
                        <h:outputLabel value="#{bundle.EditTurmaLabel_modalidade}" for="modalidade" />
                        <p:selectOneMenu id="modalidade" value="#{turmaController.selected.modalidade}" 
                                         label="#{bundle.EditTurmaTitle_modalidade}" required="true" 
                                         requiredMessage="#{bundle.EditTurmaRequiredMessage_modalidade}">
                            <f:selectItems value="#{modalidadeController.itemsAvailableSelectOne}"/>
                        </p:selectOneMenu>

                        <p:commandButton actionListener="#{turmaController.update}" update=":formTurmaList:tableTurma" 
                                         value="#{bundle.EditTurmaSaveLink}" oncomplete="dialogTurmaEdit.hide()" ajax="false" />
                        <p:commandButton value="Cancelar" oncomplete="dialogTurmaEdit.hide()" ajax="false"/>
                    </p:panelGrid>
                </p:dialog>

            </h:form>

        </ui:define>
    </ui:composition>

</html>
